import 'package:eplorex/models/activity/activity_types.dart' as actvitymodel;
import 'package:flutter/material.dart';

import 'activity_detail_page.dart';

class ActivityItem extends StatelessWidget {
  final actvitymodel.ActivityItem _activityItemModel;

  ActivityItem(this._activityItemModel);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.of(context)
            .push(MaterialPageRoute(builder: (_) => ActivityDetailsPage()));
      },
      child: Container(
        height: 160 + _activityItemModel.activitySessionSample!.length * 40.0,
        color: Colors.white,
        margin: EdgeInsets.only(left: 10, right: 10, top: 10),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Container(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  // left
                  Container(
                    height: 90,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          _activityItemModel.activityName,
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.bold),
                        ),
                        Container(
                          child: Row(
                            children: [
                              Icon(
                                Icons.location_on_outlined,
                                size: 18,
                              ),
                              Text(_activityItemModel.location)
                            ],
                          ),
                        ),
                        Container(
                          child: Wrap(
                            spacing: 8,
                            children: _activityItemModel.label == null
                                ? []
                                : _activityItemModel.label
                                    .map((e) => Text(
                                          e,
                                          style: TextStyle(
                                              color: Colors.black54,
                                              backgroundColor: Colors.black12),
                                        ))
                                    .toList(),
                          ),
                        )
                      ],
                    ),
                  ),
                  //right
                  Container(
                    width: 120,
                    padding: EdgeInsets.all(10),
                    child: Image.network(_activityItemModel.headPic),
                  )
                ],
              ),
            ),
            Container(
              height: 30,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    child: Wrap(
                      children: [
                        Text("累计"),
                        Text(_activityItemModel.totalParticipateNo.toString()),
                        Text("人报名"),
                      ],
                    ),
                  ),
                  Container(
                    child: Row(
                      children: [
                        Text(
                          "¥ ",
                          style: TextStyle(
                              color: Colors.red, fontWeight: FontWeight.w700),
                        ),
                        Text(
                          _activityItemModel.price,
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: Colors.red,
                              fontSize: 20),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(5.0)),
              ),
              height: _activityItemModel.activitySessionSample!.length * 40.0,
              child: Container(
                margin: EdgeInsets.only(left: 5, right: 5, bottom: 5),
                padding: EdgeInsets.symmetric(horizontal: 10),
                color: Colors.black12,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: _activityItemModel.activitySessionSample.map((e) {
                    return Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Container(
                          child: Wrap(
                            children: [Text(e.time)],
                          ),
                        ),
                        Text(
                            '${e.participateNo.toString()}/${e.activityCapacity.toString()}')
                      ],
                    );
                  }).toList(),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
